/*!
 * \file set_relation_visitor_base.cc
 *
 * \brief Set and Relation visitor base class that does depth-first traversal.
 *
 * \date Started: 6/8/2010
 * \date Last Modified: 7/27/2010
 * \authors Ian Craig
 */

#include <iegenlib/iegenlib.h>

namespace iegenlib{

void SRVisitor::SetCase(const Set* s){
  SetIn(s);
  s->applySpCon(this);
  SetOut(s);
}

void SRVisitor::RelationCase(const Relation* r){
  RelationIn(r);
  r->applySpCon(this);
  RelationOut(r);
}

void SRVisitor::SparseConstraintsCase(const SparseConstraints* spcon){
  SparseConstraintsIn(spcon);
  spcon->applySymbolTable(this);
  for(set<SRConjunction>::const_iterator it = spcon->conSetBegin(); 
      it != spcon->conSetEnd(); ++it){
   it->apply(this);
  }
  SparseConstraintsOut(spcon);
}

void SRVisitor::SymbolTableCase(SymbolTable* symTable){
  SymbolTableIn(symTable);
  symTable->applySTEs(this);
  SymbolTableOut(symTable);
}

void SRVisitor::SRConjunctionCase(const SRConjunction* conj){
  SRConjunctionIn(conj);
  conj->applyTuples(this);
  conj->applyEqualities(this);
  conj->applyInequalities(this);
  SRConjunctionOut(conj);
}

void SRVisitor::SREqualityCase(const SREquality* eq){
  for(int i=0; i< eq->getExpVec().get_tuplevars_size(); i++){
      int tupleName = is_tupleVar(eq->getExpVec(), i);
      if(eq->getExpVec().get_coeff(TUPLE,i) != 0 && (tupleName==111)){
         return;
      }
  }

  SREqualityIn(eq);
  eq->applyExpVec(this);
  SREqualityOut(eq);

}

void SRVisitor::SRInequalityCase(const SRInequality* ineq){
  SRInequalityIn(ineq);
  ineq->applyExpVec(this);
  SRInequalityOut(ineq);
}

void SRVisitor::ExpVecCase(const ExpVec* vec){
  ExpVecIn(vec);
  ExpVecOut(vec);
}

void SRVisitor::STECase(STE* ste){
  STEIn(ste);
  STEOut(ste);
}

void SRVisitor::TupleVarCase(TupleVar* tup){
  TupleVarIn(tup);
  TupleVarOut(tup);
}

void SRVisitor::SymConstCase(SymConst* sym){
  SymConstIn(sym);
  SymConstOut(sym);
}

void SRVisitor::ExistVarCase(ExistVar* exist){
  ExistVarIn(exist);
  ExistVarOut(exist);
}

void SRVisitor::UFCallCase(UFCall* ufcall){
  UFCallIn(ufcall);
  ufcall->applyParams(this);
  UFCallOut(ufcall);
}

void SRVisitor::TupleTypeCase(const TupleType* val) {
  TupleTypeIn(val);
  TupleTypeOut(val);
}

}//end namespace iegenlib
